﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.XtraEditors;

namespace SmsUI.N77
{
    public class CheckDog
    {
        public static List<int> SpMaType = new List<int>();

        public static bool IsSupp(int maType)
        {
            foreach (int t in SpMaType)
            {
                if (t == maType)
                {
                    return true;
                }
            }
            XtraMessageBox.Show("您的加密狗不支持该种设备类型，为了避免发送异常，请重新选择！", "警告");
            return false;
        }
        public static int AvilibalInt()
        {
            return SpMaType[0];
        }
        public static int PortCount = 99;
        public static int CheckDog2()
        {

            int ret = -1;
            //SpMaType.Add(0);
            //SpMaType.Add(1);
            //SpMaType.Add(2);
            //return 1;
            try
            {
                int findNo = NT77.NT77.NTFindFirst("sbsbm1!");
                if (findNo == 0)
                {
                    int loginNo = NT77.NT77.NTLogin("3e03d023b37f178ef052347046f33bb7");
                    if (loginNo == 0)
                    {
                        byte[] data = new byte[100];
                        NT77.NT77.NTRead(0, 100, data);
                        if (Encoding.ASCII.GetString(data).Trim().IndexOf("DTGS800") > -1)
                        {
                            SpMaType.Add(0);
                            ret = 1;
                        }
                        if (Encoding.ASCII.GetString(data).Trim().IndexOf("GSM") > -1)
                        {
                            SpMaType.Add(1);
                            ret = 1;
                        }
                        if (Encoding.ASCII.GetString(data).Trim().IndexOf("2358C") > -1)
                        {
                            SpMaType.Add(2);
                            ret = 1;
                        }
                        string ss = Encoding.ASCII.GetString(data);
                        if (ss.Trim().IndexOf("COUNT") > -1)
                        {
                            int countIndex = ss.Trim().IndexOf("COUNT");
                            string ps = ss.Substring(countIndex + 5, 2);
                            try
                            {
                                CheckDog.PortCount = int.Parse(ps);
                            }
                            catch
                            {
                            }
                        }
                        if (Encoding.ASCII.GetString(data).Trim().IndexOf("2358C") > -1)
                        {
                        }


                    }
                }
            }
            catch
            {
            }
            finally
            {
                NT77.NT77.NTLogout();
            }
            return ret;
        }
    }
}
